package com.sph.configserver.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@Slf4j
@RequestMapping(value = "crux")
public class ConfigRefreshController {
    @Autowired
    private RestTemplate restTemplate;

    @PostMapping(value = "refresh")
    public void refresh(@RequestBody String args){
        System.out.println(args);
        String uri = "http://127.0.0.1:8888/config/actuator/busrefresh";
//        restTemplate.postForObject(uri,null,String.class);
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity httpEntity = new HttpEntity(httpHeaders);
        restTemplate.exchange(uri, HttpMethod.POST,httpEntity,String.class);
    }
}
